<template>
  <svg v-if="type==='folder'" class="font-icon" :style="{opacity: opacity}" aria-hidden="true">
    <use xlink:href="#icon-folder"></use>
  </svg>
  <svg v-if="type==='file'" class="font-icon" :style="{opacity: opacity}" aria-hidden="true">
    <use :xlink:href="'#' + fileType"></use>
  </svg>
</template>

<script>
import {typeOfFile} from "./judgeFileType";

import '/public/js/fileType.js';

export default {
  name: "file-type-icon",
  props: {
    fileName: String,
    opacity: Number
  },
  data() {
    return {
      type: 'file',
      fileType: 'icon-file-other'
    }
  },
  created() {
    this.setFileType();
  },
  updated() {
    this.setFileType();
  },
  methods: {
    setFileType() {
      this.fileType = "icon-file-" + typeOfFile(this.fileName);
    }
  }
}
</script>

<style scoped>
.font-icon {
  width: 2em;
  height: 2em;
  fill: currentcolor;
  overflow: hidden;
  vertical-align: bottom;
  margin-right: 10px;
}
</style>
